package com.kyxx.topics.fragment;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.kyxx.topics.BaseApp;
import com.kyxx.topics.R;
import com.kyxx.topics.activity.DetailActivity;
import com.kyxx.topics.activity.DetailAdvertiseActivity;
import com.kyxx.topics.activity.DetailQuanActivity;
import com.kyxx.topics.activity.DetailVideoActivity;
import com.kyxx.topics.activity.ZhuanTiActivity;
import com.kyxx.topics.bean.ArticleBean;
import com.kyxx.topics.bean.TagBean;
import com.kyxx.topics.bean.TopicBean;
import com.kyxx.topics.net.OkGoRequest;
import com.kyxx.topics.net.UrlUtils;
import com.kyxx.topics.utils.Constants;
import com.kyxx.topics.utils.ScreenSizeUtils;
import com.kyxx.topics.utils.SettingUtils;
import com.kyxx.topics.utils.SizeUtils;
import com.kyxx.topics.utils.TimeUtils;
import com.kyxx.topics.widget.BannerViewPager;
import com.kyxx.topics.widget.HeaderViewPagerFragment;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.request.BaseRequest;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.wang.avi.AVLoadingIndicatorView;
import com.youth.banner.Banner;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import okhttp3.Call;
import okhttp3.Response;

public class TopicFragmentNew extends HeaderViewPagerFragment {
    private View contentView = null;
    private ExpandableListView lv;
    private View topView;
    BannerViewPager pager_banner;
    private RecyclerView rv;
    private Context context;
    private RelativeLayout rl_progress;
    private ProgressBar avi;
    private LinearLayout ll_reload;
    private int lastVisiblePosition;
    private TagBean tagBean = new TagBean();
    private List<ArticleBean> activeBeanListBanner = new ArrayList<>();
    private List<TopicBean> zhuanTiBeanList = new ArrayList<>();
    private int pageSize = 1;
    private int countSize = 20;
    private SettingUtils settingUtils = new SettingUtils();
    private ImageLoader imageLoader = ImageLoader.getInstance();
    private ExpandableListViewaAdapter expandableListViewaAdapter;
    private DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
            .cacheOnDisk(true)
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .showImageOnFail(R.mipmap.image_default)
            .showImageOnLoading(R.mipmap.image_default)
            .showImageForEmptyUri(R.mipmap.image_default)
            .build();
    private Handler parentHandler;
    private android.os.Handler handler = new android.os.Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    rl_progress.setVisibility(View.GONE);
                    break;
                case 1:
                    pager_banner.setCurrentItem(pager_banner.getCurrentItem() + 1);
                    handler.sendEmptyMessageDelayed(1, 3000);
                    break;
                case 2:
                    switch (msg.arg1) {
                        case Constants.INITDATA:
                            if (rl_progress != null)
                                rl_progress.setVisibility(View.VISIBLE);
                            if (avi != null)
                                avi.setVisibility(View.VISIBLE);
                            if (ll_reload != null)
                                ll_reload.setVisibility(View.GONE);
                            break;
                        case Constants.REFRESH:
                            if (rl_progress != null)
                                rl_progress.setVisibility(View.VISIBLE);
                            if (avi != null)
                                avi.setVisibility(View.VISIBLE);
                            if (ll_reload != null)
                                ll_reload.setVisibility(View.GONE);
                            break;
                        default:
                            if (rl_progress != null)
                                rl_progress.setVisibility(View.GONE);
                            break;
                    }
                    break;
                case 3:
                    switch (msg.arg1) {
                        case Constants.INITDATA:
                            if (rl_progress != null)
                                rl_progress.setVisibility(View.VISIBLE);
                            if (avi != null)
                                avi.setVisibility(View.VISIBLE);
                            if (ll_reload != null)
                                ll_reload.setVisibility(View.GONE);
                            break;
                        case Constants.REFRESH:
                            pageSize = 1;
                            if (rl_progress != null)
                                rl_progress.setVisibility(View.GONE);
                            if (avi != null)
                                avi.setVisibility(View.VISIBLE);
                            if (ll_reload != null)
                                ll_reload.setVisibility(View.GONE);
                            break;
                        default:
                            if (rl_progress != null)
                                rl_progress.setVisibility(View.GONE);
                            break;
                    }
                    break;
            }
        }
    };

    public static TopicFragmentNew newInstace(Bundle args) {
        TopicFragmentNew f = new TopicFragmentNew();
        f.setArguments(args);
        return f;
    }

    @Override
    public View getScrollableView() {
        return lv;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putSerializable("tag", tagBean);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (expandableListViewaAdapter != null) {
            expandableListViewaAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if (contentView == null) {
            contentView = inflater.inflate(R.layout.fragment_topic_new, container, false);
        } else {
            return contentView;
        }
        return contentView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        context = getActivity();
        Bundle bundle = getArguments();
        tagBean = (TagBean) bundle.getSerializable("tagBean");
        if (savedInstanceState != null) {
            tagBean = (TagBean) savedInstanceState.get("tag");
        }
        rl_progress = (RelativeLayout) view.findViewById(R.id.rl_progress);
        avi = (ProgressBar) view.findViewById(R.id.avi);
        ll_reload = (LinearLayout) view.findViewById(R.id.ll_reload);
        lv = (ExpandableListView) view.findViewById(R.id.lv);
        initBanner();
        expandableListViewaAdapter = new ExpandableListViewaAdapter();
        lv.setAdapter(expandableListViewaAdapter);
        initListView(Constants.INITDATA, pageSize, countSize);
        ll_reload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pageSize = 1;
                initListView(Constants.INITDATA, pageSize, countSize);
                getBannerData();
            }
        });
//        lv.setOnScrollListener(new AbsListView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(AbsListView absListView, int i) {
//
//            }
//
//            @Override
//            public void onScroll(AbsListView absListView, int i, int i1, int i2) {
//                if (lastVisiblePosition == lv.getLastVisiblePosition())
//                    return;
//                lastVisiblePosition = lv.getLastVisiblePosition();
//                Log.e("topic", lastVisiblePosition + "onScroll" + lv.getCount());
//                if (lastVisiblePosition == lv.getCount() - 2 && lv.getCount() >= countSize) {
//                    {
//                        pageSize++;
//                        initListView(Constants.LOADMORE, pageSize, countSize);
//                    }
//                }
//            }
//        });
    }

    @Override
    public void onDestroyView() {
        if (contentView != null)
            ((ViewGroup) contentView.getParent()).removeView(contentView);
        super.onDestroyView();
    }

    private void initBanner() {
        if(topView==null){
            topView = LayoutInflater.from(context).inflate(R.layout.layout_topic_banner_new, null);
            rv = (RecyclerView) topView.findViewById(R.id.rv);
            rv.setFocusable(false);
            lv.addHeaderView(topView);
        }
        getBannerData();
    }

    private void getBannerData() {
        OkGoRequest.get(UrlUtils.ACLIST, getActivity(), "aclist", CacheMode.REQUEST_FAILED_READ_CACHE, new StringCallback() {
            @Override
            public void onCacheSuccess(String s, Call call) {
                super.onCacheSuccess(s, call);
                onSuccess(s, call, null);
            }

            @Override
            public void onSuccess(String s, Call call, Response response) {
                try {
                    JSONObject result = new JSONObject(s);
                    activeBeanListBanner = JSON.parseArray(result.getJSONArray("data").toString(), ArticleBean.class);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
                    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                    rv.setLayoutManager(linearLayoutManager);
                    ActiveAdapter activeAdapter = new ActiveAdapter();
                    rv.setAdapter(activeAdapter);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }


    public void initListView(final int type, final int page, int count) {
        if (tagBean.getId() == null) {
            return;
        }
        String cacheKey = "specs&cat=" + tagBean.getId() + "&p=" + page + "&rows=" + count;
        OkGoRequest.get(UrlUtils.SPECS + "&cat=" + tagBean.getId() + "&p=" + page + "&rows=" + count, getActivity(), cacheKey, CacheMode.REQUEST_FAILED_READ_CACHE, new StringCallback() {
            @Override
            public void onBefore(BaseRequest request) {
                super.onBefore(request);
                Message msg = new Message();
                msg.what = 3;
                msg.arg1 = type;
                switch (type) {
                    case Constants.INITDATA:
                        handler.sendMessageDelayed(msg, Constants.DELAYTIMES);
                        break;
                    case Constants.REFRESH:
                        pageSize = 1;
                        handler.sendMessageDelayed(msg, Constants.DELAYTIMES);
                        break;
                    default:
                        handler.sendMessageDelayed(msg, Constants.DELAYTIMES);
                        break;
                }
            }

            @Override
            public void onAfter(@Nullable String s, @Nullable Exception e) {
                super.onAfter(s, e);
                if (parentHandler != null)
                    parentHandler.sendEmptyMessage(Constants.REFRESH);
            }

            @Override
            public void onCacheSuccess(String s, Call call) {
                super.onCacheSuccess(s, call);
                onSuccess(s, call, null);
            }

            @Override
            public void onCacheError(Call call, Exception e) {
                super.onCacheError(call, e);
                Message msg = new Message();
                msg.what = 2;
                msg.arg1 = type;
                handler.sendMessageDelayed(msg, Constants.DELAYTIMES);
            }


            @Override
            public void onSuccess(String s, Call call, Response response) {
                handler.sendEmptyMessageDelayed(0, Constants.DELAYTIMES);
                try {
                    JSONObject result = new JSONObject(s);
                    switch (type) {
                        case Constants.INITDATA:
                            zhuanTiBeanList = JSON.parseArray(result.getJSONArray("data").toString(), TopicBean.class);
                            expandableListViewaAdapter = new ExpandableListViewaAdapter();
                            lv.setAdapter(expandableListViewaAdapter);
                            break;
                        case Constants.LOADMORE:
                            zhuanTiBeanList.addAll(JSON.parseArray(result.getJSONArray("data").toString(), TopicBean.class));
                            expandableListViewaAdapter.notifyDataSetChanged();
                            break;
                        case Constants.REFRESH:
                            pageSize = 1;
                            zhuanTiBeanList = JSON.parseArray(result.getJSONArray("data").toString(), TopicBean.class);
                            expandableListViewaAdapter = new ExpandableListViewaAdapter();
                            lv.setAdapter(expandableListViewaAdapter);
                            break;
                    }
                    lastVisiblePosition = lv.getLastVisiblePosition();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    class TopicAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return zhuanTiBeanList.size();
        }

        @Override
        public Object getItem(int i) {

            return zhuanTiBeanList.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder holder;
            if (view == null) {
                holder = new ViewHolder();
                view = View.inflate(context, R.layout.item_topic, null);
                holder.tv_tab = (TextView) view.findViewById(R.id.tv_tab);
                holder.tv_title = (TextView) view.findViewById(R.id.tv_title);
                holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
                holder.tv_content = (TextView) view.findViewById(R.id.tv_content);
                holder.tv_like = (TextView) view.findViewById(R.id.tv_like);
                holder.civ_avtar = (ImageView) view.findViewById(R.id.civ_avtar);
                holder.iv_cover = (ImageView) view.findViewById(R.id.iv_cover);
                holder.line = view.findViewById(R.id.line);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            if (zhuanTiBeanList.get(i).getImgurl() != null) {
                imageLoader.displayImage(UrlUtils.BASEHTTP + zhuanTiBeanList.get(i).getImgurl().getPath(), holder.iv_cover, options);
            } else {
                imageLoader.displayImage("", holder.iv_cover, options);
            }
            holder.tv_title.setText(zhuanTiBeanList.get(i).getTitle());
            holder.tv_content.setText(zhuanTiBeanList.get(i).getDemo());
            holder.tv_tab.setText(zhuanTiBeanList.get(i).getTag());
            return view;
        }
    }

    class ViewHolder {
        private TextView tv_tab;
        private TextView tv_title;
        private TextView tv_name;
        private TextView tv_content;
        private TextView tv_like;
        private ImageView iv_cover;
        private ImageView civ_avtar;
        private RelativeLayout rl_expand;
        private ImageView iv_expand;
        private View line;
    }

    class ActiveAdapter extends RecyclerView.Adapter<ViewHolderActive> {
        @Override
        public ViewHolderActive onCreateViewHolder(ViewGroup parent, int viewType) {
            View view =
                    LayoutInflater.from(parent.getContext()).inflate(R.layout.item_topic_hor_scroll, parent, false);
            ViewHolderActive holder = new ViewHolderActive(view);
            return holder;
        }

        @Override
        public void onBindViewHolder(ViewHolderActive holder, final int i) {
            if (i == activeBeanListBanner.size() - 1) {
                holder.view_1.setVisibility(View.VISIBLE);
            }
            if (activeBeanListBanner.get(i).getImgurl() != null) {
                imageLoader.displayImage(UrlUtils.BASEHTTP + activeBeanListBanner.get(i).getImgurl().getPath(), holder.iv_cover, options);
            } else {
                imageLoader.displayImage("", holder.iv_cover, options);
            }
            holder.tv_name.setText(Html.fromHtml(activeBeanListBanner.get(i).getTitle()));
            holder.iv_cover.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (!TextUtils.isEmpty(activeBeanListBanner.get(i).getVideo())) {
                        Intent intent = new Intent(context, DetailVideoActivity.class);
                        intent.putExtra("title", activeBeanListBanner.get(i).getTitle());
                        intent.putExtra("id", activeBeanListBanner.get(i).getId());
                        if (activeBeanListBanner.get(i).getImgurl() == null) {
                            intent.putExtra("imageUrl", "");
                        } else {
                            intent.putExtra("imageUrl", UrlUtils.BASEHTTP + activeBeanListBanner.get(i).getImgurl().getPath());
                        }
                        intent.putExtra("videoUrl", activeBeanListBanner.get(i).getVideo());
                        intent.putExtra("fav_position", i);
                        startActivityForResult(intent, 0);
                        addBrowseLog(activeBeanListBanner.get(i).getId());
                        return;
                    }
                    if (activeBeanListBanner.get(i).getType() == 4) {
                        Intent intent = new Intent(context, DetailQuanActivity.class);
                        intent.putExtra("title", activeBeanListBanner.get(i).getTitle());
                        intent.putExtra("id", activeBeanListBanner.get(i).getId());
                        startActivity(intent);
                    } else if (activeBeanListBanner.get(i).getType() == 5) {
                        Intent intent = new Intent(context, DetailAdvertiseActivity.class);
                        intent.putExtra("title", activeBeanListBanner.get(i).getTitle());
                        intent.putExtra("id", activeBeanListBanner.get(i).getId());
                        startActivity(intent);
                    } else {
                        Intent intent = new Intent(context, DetailActivity.class);
                        intent.putExtra("title", activeBeanListBanner.get(i).getTitle());
                        intent.putExtra("id", activeBeanListBanner.get(i).getId());
                        startActivity(intent);
                    }
                    addBrowseLog(activeBeanListBanner.get(i).getId());
                }
            });

        }

        @Override
        public int getItemCount() {
            return activeBeanListBanner.size();
        }
    }

    public static class ViewHolderActive extends RecyclerView.ViewHolder {
        ImageView iv_cover;
        TextView tv_name;
        View view_1;

        public ViewHolderActive(View view) {
            super(view);
            iv_cover = (ImageView) view.findViewById(R.id.iv_cover);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            view_1 = (View) view.findViewById(R.id.view_1);
        }
    }

    public class ExpandableListViewaAdapter extends BaseExpandableListAdapter {
        @Override
        public int getGroupCount() {
            return zhuanTiBeanList == null ? 0 : zhuanTiBeanList.size();
        }

        @Override
        public int getChildrenCount(int i) {
            return zhuanTiBeanList.get(i).getDoc() == null ? 0 : zhuanTiBeanList.get(i).getDoc().size();
        }

        @Override
        public Object getGroup(int i) {
            return zhuanTiBeanList == null ? null : zhuanTiBeanList.get(i);
        }

        @Override
        public Object getChild(int i, int i1) {
            return zhuanTiBeanList.get(i).getDoc() == null ? null : zhuanTiBeanList.get(i).getDoc().get(i1);
        }

        @Override
        public long getGroupId(int i) {
            return i;
        }

        @Override
        public long getChildId(int i, int i1) {
            return zhuanTiBeanList.get(i).getDoc() == null ? 0 : i1;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }

        @Override
        public View getGroupView(final int i, final boolean b, View view, ViewGroup viewGroup) {
            ViewHolder holder;
            if (view == null) {
                holder = new ViewHolder();
                view = View.inflate(context, R.layout.item_topic, null);
                holder.tv_tab = (TextView) view.findViewById(R.id.tv_tab);
                holder.tv_title = (TextView) view.findViewById(R.id.tv_title);
                holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
                holder.tv_content = (TextView) view.findViewById(R.id.tv_content);
                holder.tv_like = (TextView) view.findViewById(R.id.tv_like);
                holder.civ_avtar = (ImageView) view.findViewById(R.id.civ_avtar);
                holder.iv_cover = (ImageView) view.findViewById(R.id.iv_cover);
                holder.rl_expand = (RelativeLayout) view.findViewById(R.id.rl_expand);
                holder.iv_expand = (ImageView) view.findViewById(R.id.iv_expand);
                holder.line = view.findViewById(R.id.line);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
//            ViewGroup.LayoutParams layoutParams = holder.iv_cover.getLayoutParams();
//            layoutParams.width = ScreenSizeUtils.getInstance(context).getScreenWidth();
//            layoutParams.height = ScreenSizeUtils.getInstance(context).getScreenWidth() * 450 / 755;
//            holder.iv_cover.setLayoutParams(layoutParams);
//            if (i == 0) {
//                holder.line.setVisibility(View.GONE);
//            } else {
//                holder.line.setVisibility(View.VISIBLE);
//            }
            switch (settingUtils.getZiTiDaXiao()) {
                case 0:
                    holder.tv_content.setTextSize(14);
                    break;
                case 1:
                    holder.tv_content.setTextSize(18);
                    break;
                case 2:
                    holder.tv_content.setTextSize(22);
                    break;
            }
//            if (b) {
//                holder.iv_expand.setImageDrawable(getResources().getDrawable(R.drawable.ic_topic_coll));
//            } else {
//                holder.iv_expand.setImageDrawable(getResources().getDrawable(R.drawable.ic_topic_expand));
//            }
            //            holder.rl_expand.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    if (b) {
//                        lv.collapseGroup(i);
//                    } else {
//                        lv.expandGroup(i);
////                        lv.setSelection(i + 1);
//                    }
//                }
//            });
            lv.expandGroup(i);
            holder.iv_expand.setImageDrawable(getResources().getDrawable(R.drawable.ic_topic_expand));
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(getActivity(), ZhuanTiActivity.class);
                    intent.putExtra("title", zhuanTiBeanList.get(i).getTitle());
                    intent.putExtra("demo", zhuanTiBeanList.get(i).getDemo());
                    intent.putExtra("imgUrl", UrlUtils.BASEHTTP + zhuanTiBeanList.get(i).getImgurl().getPath());
                    intent.putExtra("sid", zhuanTiBeanList.get(i).getId());
                    startActivity(intent);
                }
            });


            if (zhuanTiBeanList.get(i).getImgurl() != null) {
                imageLoader.displayImage(UrlUtils.BASEHTTP + zhuanTiBeanList.get(i).getImgurl().getPath(), holder.iv_cover, options);
            } else {
                imageLoader.displayImage("", holder.iv_cover, options);
            }
            holder.tv_title.setText(Html.fromHtml(zhuanTiBeanList.get(i).getTitle()));
            holder.tv_content.setText(Html.fromHtml(zhuanTiBeanList.get(i).getDemo()));
            if (TextUtils.isEmpty(zhuanTiBeanList.get(i).getTag())) {
                holder.tv_tab.setText("原创");
            } else {
                holder.tv_tab.setText(zhuanTiBeanList.get(i).getTag());
            }
            return view;
        }

        @Override
        public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
            view = View.inflate(context, R.layout.item_zhuanti, null);
            ImageView iv_zhuanti = (ImageView) view.findViewById(R.id.iv_zhuanti);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            TextView tv_day = (TextView) view.findViewById(R.id.tv_day);
            TextView tv_num = (TextView) view.findViewById(R.id.tv_num);
            ImageView iv_focus = (ImageView) view.findViewById(R.id.iv_focus);
            TextView tv_read_num = (TextView) view.findViewById(R.id.tv_read_num);
            final TopicBean.DocBean docBean = zhuanTiBeanList.get(i).getDoc().get(i1);
            if (docBean.getImgurl() != null) {
                imageLoader.displayImage(UrlUtils.BASEHTTP + docBean.getImgurl(), iv_zhuanti, options);
            } else {
                imageLoader.displayImage("", iv_zhuanti, options);
            }
            switch (settingUtils.getZiTiDaXiao()) {
                case 0:
                    tv_title.setTextSize(13);
                    break;
                case 1:
                    tv_title.setTextSize(17);
                    break;
                case 2:
                    tv_title.setTextSize(21);
                    break;
            }
            tv_num.setText(docBean.getComment());
            tv_read_num.setText(docBean.getView());
            tv_title.setText(Html.fromHtml(docBean.getTitle()));
            tv_day.setText(TimeUtils.milliseconds2String(Long.valueOf(docBean.getAddtime()) * 1000, new SimpleDateFormat("MM-dd HH:mm")));
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, DetailActivity.class);
                    intent.putExtra("id", docBean.getAid());
                    intent.putExtra("title", docBean.getTitle());
                    startActivity(intent);
                    addBrowseLog(docBean.getAid());
                }
            });
//            tv_num.setText(articleBeanList.get(i).getComment());
            return view;
        }

        @Override
        public boolean isChildSelectable(int i, int i1) {
            return false;
        }
    }

    public void setValue(TagBean tagBean) {
        this.tagBean = tagBean;
    }

    public void setHandler(Handler handler) {
        this.parentHandler = handler;
    }

    private void addBrowseLog(String id) {
        if (TextUtils.isEmpty(BaseApp.getModel().getId()))
            return;
        HttpParams params = new HttpParams();
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("uid", BaseApp.getModel().getId());
        jsonObject.put("news_id", id);
        params.put("json", jsonObject.toString());
        OkGoRequest.post(UrlUtils.addBrowseLog, getActivity(), "addBrowseLog", CacheMode.NO_CACHE, params, new StringCallback() {
            @Override
            public void onSuccess(String s, Call call, Response response) {

            }
        });
    }
}
